package giit.computerbase.dao;

/**
 * This class is for connection MySQL database<br>
 * User: tum0r
 * Package Name: giit.computerbase.dao
 * Time: 2018/10/28 Sunday 18:05:32
 */

import java.sql.DriverManager;
import java.sql.SQLException;

public class MySQL extends SQL {

    public MySQL() throws ClassNotFoundException {
        Class.forName("com.mysql.jdbc.Driver");
    }

    @Override
    public boolean open(String host, int port, String dabaseName, String encode, String userName, String password) {
        StringBuffer url = new StringBuffer();
        url.append("jdbc:mysql://");
        url.append(host);
        url.append(":");
        url.append(String.valueOf(port));
        url.append("/");
        url.append(dabaseName);
        url.append("?useUnicode=true&useSSL=false&allowPublicKeyRetrieval=true&characterEncoding=");
        url.append(encode);
        url.append("&user=");
        url.append(userName);
        url.append("&password=");
        url.append(password);

        try {
            connection = DriverManager.getConnection(url.toString());
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

}
